<?php
/**
 * Created by PhpStorm.
 * User: XD
 * Date: 2017/8/31
 * Time: 16:40
 */
namespace app\mysql\app;
//顶层目录路径，及模块层目录

function getTopDir(){
    $TopDirectory = __DIR__;
    $arraydir = explode(DIRECTORY_SEPARATOR,$TopDirectory);
    $arraydir2 = array_splice($arraydir,0,count($arraydir)-2);  //从第一个开始，取n个
    $TopDirectory = implode(DIRECTORY_SEPARATOR,$arraydir2);
    return $TopDirectory;  //返回项目级目录
}

function autoLoadClass($className)
{
    //echo "调用一次";
    $dir = array("base","builder","model","config");
    $bool = true;
    $i = 0;
    //echo $className;
    do{
        $array = explode(DIRECTORY_SEPARATOR,$className);
        $filename = $array[count($array)-1];
        $file = getTopDir().DIRECTORY_SEPARATOR."mysql".DIRECTORY_SEPARATOR."app".DIRECTORY_SEPARATOR.$dir[$i].DIRECTORY_SEPARATOR.$filename.".php";
        //echo "file: $file";
        //echo "当前状态值：bool : $bool , i:$i ， file: $file";
        $i++;
        if(file_exists($file)){
            //echo "判断进入，应该跳出循环了";
            require_once ($file);
            $bool = false;
        }
    }while($bool);
}

//include "../../log/initLog.php";   //在初始化时如果外部初始化文件引入了log，此条不启用
spl_autoload_register('\app\mysql\app\autoLoadClass');

?>

